package com.bootdo.appsystem.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.appsystem.domain.UserauthsDO;
import com.bootdo.appsystem.service.UserauthsService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author xiaoxiao
 * @email 806191255@qq.com
 * @date 2018-05-12 14:42:14
 */
 
@Controller
@RequestMapping("/appsystem/userauths")
public class UserauthsController {
	@Autowired
	private UserauthsService userauthsService;
	
	@GetMapping()
	@RequiresPermissions("appsystem:userauths:userauths")
	String Userauths(){
	    return "appsystem/userauths/userauths";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("appsystem:userauths:userauths")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<UserauthsDO> userauthsList = userauthsService.list(query);
		int total = userauthsService.count(query);
		PageUtils pageUtils = new PageUtils(userauthsList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("appsystem:userauths:add")
	String add(){
	    return "appsystem/userauths/add";
	}

	@GetMapping("/edit/{authsid}")
	@RequiresPermissions("appsystem:userauths:edit")
	String edit(@PathVariable("authsid") Integer authsid,Model model){
		UserauthsDO userauths = userauthsService.get(authsid);
		model.addAttribute("userauths", userauths);
	    return "appsystem/userauths/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("appsystem:userauths:add")
	public R save( UserauthsDO userauths){
		if(userauthsService.save(userauths)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("appsystem:userauths:edit")
	public R update( UserauthsDO userauths){
		userauthsService.update(userauths);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("appsystem:userauths:remove")
	public R remove( Integer authsid){
		if(userauthsService.remove(authsid)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("appsystem:userauths:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] authsids){
		userauthsService.batchRemove(authsids);
		return R.ok();
	}
	
}
